{include file="public/meta" /} 
<title>编辑文章 - 文章管理</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-article-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$articleInfo['title']}" placeholder="输入文章标题" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章分类：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="category_id" id="category_id" class="select">
					<option value="0">请选择文章分类</option>
					{volist name="categoryList" id="val"}
					<option value="{$val['id']}">{$val['title']}</option>
					{/volist}
				</select>
				</span> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">排序值：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$articleInfo['sort']}" placeholder="" id="sort" name="sort">
			</div>
		</div>
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>封面图：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="btn-upload form-group">
				<input class="input-text upload-url" type="text" name="img_url" id="img_url" nullmsg="请添加图片" style="width:400px" value="{$articleInfo['img_url']}">
				<a href="javascript:void(0);" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i> 封面图</a>
                <input type="file" name="file-1" class="input-file" id="img-url-file"></span>
            </div>
        </div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">文章摘要：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="summary" id="summary" cols="" rows="" class="textarea"  placeholder="请输入该篇文章的描述" datatype="*10-200" dragonfly="true" nullmsg="摘要不能为空！">{$articleInfo['summary']}</textarea>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">作者来源：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$articleInfo['author']}" placeholder="文章作者来源" id="author" name="author">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">文章内容：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<script id="content" type="text/plain" style="width:100%;height:400px;"></script> 
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button onClick="article_save();" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存提交</button>
				<button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</article>
<!--_footer 作为公共模版分离出去-->
{include file="public/footer" /} 
<!--/_footer /作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>   
<script type="text/javascript" src="__LIB__/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script> 
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script> 
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	var ue = UE.getEditor('content');
	ue.addListener("ready", function () {
        // editor准备好之后才可以使用setCOntent
        UE.getEditor('content').setContent('{$articleInfo['content']}');
	});
	$("#category_id").val({$articleInfo['category_id']});
	
});
function article_save(){
	var cid=parseInt($('#category_id').val());
	if(cid==0){
		alert('请选择文章分类');
		return false;
	}
    var content=UE.getEditor('content').getContent();
    $.ajax({
        url:"{:url('Article/editsave')}",
        type:"post",
        data:{
            'id':{$articleInfo['id']},
			'title':$('#title').val(),
            'author':$('#author').val(),
            'category_id':$('#category_id').val(),
            'sort':$('#sort').val(),
            'summary':$('#summary').val(),
			'img_url': $('#img_url').val(),
            'content':content
        },
        dataType:"json",
        success:function(data){
            
            if(data.code==0)
            {
                parent.layer.msg(data.msg,{icon:6,time:1000});
                var index = parent.layer.getFrameIndex(window.name);
                parent.window.location.reload();
                parent.layer.close(index);
            }
            else
            {
                parent.layer.msg(data.msg,{icon:5,time:1000});
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        },
        error:function(data){
            layer.msg('500系统错误，请联系管理员！',{icon:5,time:1000});
        }
    });
}
//单图片上传
        $('#img-url-file').change(function() {
            var filess = $('#img-url-file')[0].files[0]
            console.log(filess);
            var fm = new FormData();
            fm.append('image', filess);
            $.ajax({
                type: 'post',
                url: "{:url('Common/uploadImage')}",
                data: fm,
                processData: false,
                contentType: false,
                success: function(data) {
                    //alert(data);
                    var jdata = JSON.parse(data);
                    if (jdata.code == 0)
                    {
                        parent.layer.msg(jdata.msg, {
                            icon: 6,
                            time: 1000
                        });
                        var imgurl = jdata.data;
                        imgurl = imgurl.replace(/\\/g, "/");
                        $('#img_url').val(imgurl);
                    } else {
                        parent.layer.msg(jdata.msg, {
                            icon: 5,
                            time: 1000
                        });
                    }
                },
                error: function(data) {
                    layer.msg('500系统错误，请重试！', {
                        icon: 5,
                        time: 1000
                    });
                }
            });
        });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>